package com.tanhua.admin.controller;

import com.tanhua.admin.service.ManagerService;
import com.tanhua.model.domain.UserInfo;
import com.tanhua.model.mongo.Movement;
import com.tanhua.model.vo.MovementsVo;
import com.tanhua.model.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

@RestController
@RequestMapping("/manage")
public class ManagerController {

    @Autowired
    private ManagerService managerService;


    @GetMapping("/users")
    public ResponseEntity users(@RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer pagesize) {
        PageResult result = managerService.findAllUsers(page,pagesize);
        return ResponseEntity.ok(result);
    }

    /**
     * 根据id查询用户详情
     *
     * @param userId
     * @return
     */
    @GetMapping("/users/{userId}")
    public ResponseEntity findUserById(@PathVariable("userId") Long userId) {
        UserInfo userInfo = managerService.findUserById(userId);
        return ResponseEntity.ok(userInfo);
    }

    /**
     * 查询指定用户发布的所有视频列表
     */
    @GetMapping("/videos")
    public ResponseEntity videos(@RequestParam(defaultValue = "1") Integer page,
                                 @RequestParam(defaultValue = "10") Integer pagesize,
                                 Long uid ) {
        PageResult result = managerService.findAllVideos(page,pagesize,uid);
        return ResponseEntity.ok(result);
    }

    //查询动态
    @GetMapping("/messages")
    public ResponseEntity messages(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10") Integer pagesize,
                                   Long uid,Integer state) {
        PageResult result = managerService.findAllMovements(page,pagesize,uid,state);
        return ResponseEntity.ok(result);
    }

    //用户冻结
    @PostMapping("/users/freeze")
    public ResponseEntity freeze(@RequestBody Map params) {
        Map map =  managerService.userFreeze(params);
        return ResponseEntity.ok(map);
    }

    //用户解冻
    @PostMapping("/users/unfreeze")
    public ResponseEntity unfreeze(@RequestBody  Map params) {
        Map map =  managerService.userUnfreeze(params);
        return ResponseEntity.ok(map);
    }

    //评论列表翻页
    @GetMapping("/messages/comments")
    public ResponseEntity comment(@RequestParam(defaultValue = "1") Integer page,
                                  @RequestParam(defaultValue = "10") Integer pagesize,
                                  String messageID){
        PageResult pr = managerService.findComments(messageID, page, pagesize);
        return ResponseEntity.ok(pr);
    }

    //1.动态详情
    @GetMapping("/messages/{id}")
    public ResponseEntity messagesById(@PathVariable("id") String id){
        MovementsVo vo = managerService.messagesById(id);
        return ResponseEntity.ok(vo);
    }

    //2.通过审核
    @PostMapping("/messages/pass")
    public ResponseEntity pass(@RequestBody String[] param){
        return managerService.pass(param);
    }

    //3.动态拒绝
    @PostMapping("/messages/reject")
    public ResponseEntity reject (@RequestBody String[] param){
        return managerService.reject(param);
    }
    //4.置顶
    @PostMapping("/messages/{id}/top")
    public ResponseEntity top(@PathVariable("id") String id){
        Movement movement = managerService.top(id);
        return ResponseEntity.status(200).body("置顶成功");
    }
    //5.取消置顶
    @PostMapping("/messages/{id}/untop")
    public ResponseEntity topop(@PathVariable("id") String id){
        Movement movement = managerService.untop(id);
        return ResponseEntity.status(200).body("取消置顶成功");
    }
}
